//
//  SISSNetworkingManager+Message.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/4.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSNetworkingManager+Message.h"
#import "SISSLatestNotificationModel.h"
#import "SISSNotificationRecordModel.h"

@implementation SISSNetworkingManager (Message)

// 5.1.1 获取im账号 GET请求
- (void)requestIMAccountWithSuccess:(void (^)(NSDictionary *))successBlock failed:(void (^)(NSError *))failedBlock {
        NSDictionary *parameters = @{
                                 @"saId":[SISSUserAccount shared].saId,
                                 @"type":@1
                                 };
    
    [kNetworkManager GETWithURLString:URL_IM_ACCOUNT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"5.1.1 获取im账号: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
            if (failedBlock) {
                failedBlock(responseObject);
            }
            return ;
        }
        
        NSDictionary *data = responseObject[@"data"];
        
        if (successBlock) {
            successBlock(data);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 5.3.1 获取最新协会公告 GET请求
- (void)requestLatestNoticeRecordWithSuccess:(void (^)(SISSLatestNotificationModel *))successBlock failed:(void (^)(NSError *))failedBlock {
        NSDictionary *parameters = @{};
    
    [kNetworkManager GETWithURLString:URL_GET_LATEST_NOTICE_ROCORD parameters:parameters success:^(id responseObject) {
        
        NSLog(@"5.3.1 获取最新协会公告 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSLatestNotificationModel *model = [SISSLatestNotificationModel yy_modelWithJSON:dataDict];
        
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 5.3.2 获取最新系统消息 GET请求
- (void)requestLastSystemMessageWithSuccess:(void (^)(SISSLatestNotificationModel *))successBlock failed:(void (^)(NSError *))failedBlock {    NSDictionary *parameters = @{
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager GETWithURLString:URL_GET_LATEST_SYSTEM_MESSAGE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"5.3.2 获取最新系统消息 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSLatestNotificationModel *model = [SISSLatestNotificationModel yy_modelWithJSON:dataDict];
        
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 5.3.3 获取协会公告 GET请求
- (void)requestNoticeRecordWithSuccess:(void (^)(NSArray<SISSNotificationRecordModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
        NSDictionary *parameters = @{};
    
    [kNetworkManager GETWithURLString:URL_GET_NOTICE_ROCORD parameters:parameters success:^(id responseObject) {
        
        NSLog(@"5.3.3 获取协会公告 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *notiRecordArr = [NSArray yy_modelArrayWithClass:[SISSNotificationRecordModel class] json:dataArr];
        
        if (successBlock) {
            successBlock(notiRecordArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 5.3.4 获取系统消息 GET请求
- (void)requestSystemMessageWithSuccess:(void (^)(NSArray<SISSNotificationRecordModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
        NSDictionary *parameters = @{
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager GETWithURLString:URL_GET_SYSTEM_MESSAGE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"5.3.4 获取系统消息 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *notiRecordArr = [NSArray yy_modelArrayWithClass:[SISSNotificationRecordModel class] json:dataArr];
        
        if (successBlock) {
            successBlock(notiRecordArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 5.3.5 清空系统消息 GET请求
- (void)clearSystemMessageWithSuccess:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
        NSDictionary *parameters = @{
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager GETWithURLString:URL_CLEAR_SYSTEM_MESSAGE parameters:parameters success:^(id responseObject) {
        NSLog(@"5.3.5 清空系统消息 GET请求: responseObject-->%@",responseObject);
        
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

@end
